﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Survey_SurveyAdd : System.Web.UI.Page
{
    protected string action = "";
    protected int SurveyID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        action = NetRequest.GetQueryString("Action");
        SurveyID = NetRequest.GetQueryInt("SurveyID");

        if (!IsPostBack)
        {
            switch (action)
            {
                case "Add": break;
                case "Modify":
                    BindData();
                    btnSumbit.Text = "更新";
                    break;
                case "Delete":
                    BindData();
                    btnSumbit.Text = "删除";
                    btnSumbit.Attributes.Add("onclick", "return confirm('确定要删除吗？');");
                    break;
            }
        }
    }

    private void BindData()
    {
        Whir.BLL.Whir_Survey bll = new Whir.BLL.Whir_Survey();
        Whir.Model.Whir_Survey model = bll.GetModel(SurveyID);
        this.txtSurveyTitle.Text = model.SurveyTitle;
        this.RadioButtonList1.SelectedValue = model.SurveyType.ToString();
        this.RadioButtonList2.SelectedValue = model.SurveyShowType.ToString();
        this.CheckBox1.Checked = model.IsShow;
        this.txtDate.Text = model.CreateDate.ToString();
    }

    protected void btnSumbit_Click(object sender, EventArgs e)
    {
        Whir.BLL.Whir_Survey bll = new Whir.BLL.Whir_Survey();
        Whir.Model.Whir_Survey model;
        switch (action)
        {
            case "Add":
                model = new Whir.Model.Whir_Survey();
                model.SurveyTitle = txtSurveyTitle.Text;
                model.SurveyType = Convert.ToInt32(this.RadioButtonList1.SelectedValue);
                model.SurveyShowType = Convert.ToInt32(this.RadioButtonList2.SelectedValue);
                model.IsShow = this.CheckBox1.Checked;
                model.CreateDate = DateTime.Parse(txtDate.Text);
                bll.Add(model);
                break;
            case "Modify":
                model = bll.GetModel(SurveyID);
                model.SurveyTitle = txtSurveyTitle.Text; 
                model.SurveyType = Convert.ToInt32(this.RadioButtonList1.SelectedValue);
                model.SurveyShowType = Convert.ToInt32(this.RadioButtonList2.SelectedValue);
                model.IsShow = this.CheckBox1.Checked;
                model.CreateDate = DateTime.Parse(txtDate.Text);
                bll.Update(model);
                break;
            case "Delete":
                model = bll.GetModel(SurveyID);
                if (model != null)
                {
                    bll.Delete(SurveyID);
                }
                break;
        }

        Response.Redirect("Default.aspx");
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}
